#ifndef _APPS_BBOXD_CCLIENT_H_
#define _APPS_BBOXD_CCLIENT_H_

#include <buola/bbox/protocol/casyncconnection.h>

namespace buola { namespace bboxd {

class CMaster;

class CClient : public bbox::protocol::CAsyncConnection
{
public:
    CClient(CMaster *pMaster,io::PSocket pSocket);
    ~CClient();

public:
    const std::string &Name()   {   return mName;       }
    uint64_t UID()              {   return mUID;        }

    void SendClientConnection(io::PSocket pSocket,uint64_t pOther);
    
private:
    void DoGetService(bbox::protocol::CPacket &pPacket);
    void DoRegisterService(bbox::protocol::CPacket &pPacket);
    void DoUnregisterService(bbox::protocol::CPacket &pPacket);
    void DoConnectToClient(bbox::protocol::CPacket &pPacket);
    
    void OnPacket(bbox::protocol::CPacket &pPacket) override;
    void OnReply(bbox::protocol::CPacket &pPacket) override;
    
    void OnEOF() override;
    void OnHello(const std::string &pPeerName) override;
    
    CMaster *mMaster;

    std::string mName;
    uint64_t mUID;
};

/*namespace bboxd*/ } /*namespace buola*/ }

#endif
